function renderSensorGraphs() {
    console.log('开始绘制图表');
    $.ajax({
        url: "{{ url_for('get_big_sensor_data') }}",
        method: 'GET',
        success: function(data) {
            // 清空之前的图表容器
            $('.big-sensor-graphs').empty();
            
            // 获取容器宽度，计算图表应有的宽度
            let chartWidth = 600; // 固定宽度为600像素
            let spacing = 10; // 设置间距为10像素

            // 准备数据
            var labels = [];
            var datasets = [];

            // 遍历每个传感器的数据
            for (var sensor in data) {
                if (data.hasOwnProperty(sensor)) {
                    var sensorData = data[sensor];
                    labels = sensorData.map(function(entry) {
                        return entry.Time;
                    });

                    // 生成伪随机颜色
                    var color = generateColorFromString(sensor);

                    // 添加数据集
                    datasets.push({
                        label: sensor,
                        data: sensorData.map(function(entry) {
                            return entry.Data;
                        }),
                        borderColor: color,
                        backgroundColor: 'rgba(' + hexToRgb(color).join(',') + ', 0.1)',
                        fill: true,
                        lineTension: 0.1
                    });
                }
            }

            // 创建唯一的canvas id
            var canvasId = 'combined-chart-canvas';
            var canvasHtml = `
                <div style="flex: 0 0 ${chartWidth}px; max-width: ${chartWidth}px; padding: 0;">
                    <canvas id="${canvasId}" width="${chartWidth}" height="250" style="display: block; width: 100%!important;"></canvas>
                </div>
            `;
            $('.sensor-graphs').append(canvasHtml);
            
            // 绘制图表
            var ctx = document.getElementById(canvasId).getContext('2d');
            var chart = new Chart(ctx, {
                type: 'line',
                data: {
                    labels: labels,
                    datasets: datasets
                },
                options: {
                    legend: {
                        display: true // 显示图例
                    },
                    pointBackgroundColor: 'transparent',
                    pointBorderColor: 'transparent',
                    responsive: true,
                    maintainAspectRatio: true,
                    animation: {
                        duration: 0 // 禁用动画
                    },
                    scales: {
                        xAxes: [{
                            type: 'time',
                            time: {
                                unit: 'second', // 将时间单位改为秒
                                displayFormats: {
                                    second: 'ss' // 设置时间显示格式为秒
                                }
                            },
                            ticks: {
                                maxTicksLimit: 10
                            }
                        }],
                        yAxes: [{
                            ticks: {
                                beginAtZero: true
                            }
                        }]
                    }
                }
            });
            
            // 检查图表是否成功绘制
            if (chart instanceof Chart) {
                console.log('图表绘制成功:', chart);
            } else {
                console.error('图表绘制失败');
            }
        },
        error: function(xhr) {
            console.log("获取传感器数据失败: ", xhr.statusText);
        }
    });
}

// 辅助函数：根据字符串生成伪随机颜色
function generateColorFromString(str) {
    var hash = 0;
    for (var i = 0; i < str.length; i++) {
        hash = str.charCodeAt(i) + ((hash << 5) - hash);
    }
    var color = (hash & 0xFFFFFF) | 0x800000; // 确保颜色不透明
    return '#' + color.toString(16).substring(1);
}

// 辅助函数：将十六进制颜色转换为RGB数组
function hexToRgb(hex) {
    var bigint = parseInt(hex.slice(1), 16);
    var r = (bigint >> 16) & 255;
    var g = (bigint >> 8) & 255;
    var b = bigint & 255;
    return [r, g, b];
}